<?php

include_once("games.php");

class User {
	var $id, $login, $email, $score, $rank, $gamesId;
	/**
	 * Games object
	 */
	var $games;

	public function User() {
		if (DEBUG) enex("User::User()");
	}

	/**
	 * @param userString User serialized to String - each value separeted by space
	 */
	public function buildFromString($userString) {
		if (DEBUG) enter("User::buildFromString()");
		list($this->id, $this->login, $this->email, $this->score, $this->rank, $gamesIds) = split(" ", $userString);
		$this->gamesId = split(";", $gamesIds);
		$gms = new Games();
		$this->games = $gms->buildFromFilePartially(GAMES, $this->gamesId);
		if (DEBUG) ex("User::buildFromString()");
		return $this;
	}

	public function buildFromValues($id, $login, $email, $score, $rank, $gamesId) {
		if (DEBUG) enter("User::buildFromValues($id, $login, $email, $score, $rank, $gamesId)");
		$this->id = $id;
		$this->login = $login;
		$this->email = $email;
		$this->score = $score;
		$this->rank = $rank;
		$this->gamesId = $gamesId;
		if (DEBUG) ex("User::buildFromValues($id, $login, $email, $score, $rank, $gamesId)");
	}

	public function toString() {
		if (DEBUG) enter("User::toString()");
		$gamesIds = implode(";", $this->gamesId);
		if (DEBUG) ex("User::toString()");
		return "$this->id $this->login $this->email $this->score $this->rank $gamesIds";
	}

	public function getId() {
		if (DEBUG) enex("User::getId()");
		return $this->id;
	}

	public function getLogin() {
		if (DEBUG) enex("User::getLogin()");
		return $this->login;
	}

	public function getEmail() {
		if (DEBUG) enex("User::getEmail()");
		return $this->email;
	}

	public function getScore() {
		if (DEBUG) enex("User::getScore()");
		return $this->score;
	}

	public function getRank() {
		if (DEBUG) enex("User::getRank()");
		return $this->rank;
	}

	public function getGames() {
		if (DEBUG) enex("User::getGames()");
		return $this->games;
	}

	public function getGamesId() {
		if (DEBUG) enex("User::getGamesId()");
		return $this->gamesId;
	}

	public function setId($newId) {
		$this->id = $newId;
		if (DEBUG) enex("User::setId()");
	}

	public function setLogin($newLogin) {
		$this->login = $newLogin;
		if (DEBUG) enex("User::setLogin()");
	}

	public function setEmail($newEmail) {
		$this->email = $newEmail;
		if (DEBUG) enex("User::setEmail()");
	}

	public function setScore($newScore) {
		$this->score = $newScore;
		if (DEBUG) enex("User::setScore()");
	}

	public function setRank($newRank) {
		$this->rank = $newRank;
		if (DEBUG) enex("User::setRank()");
	}

	public function setGames($newGames) {
		$this->games = $newGames;
		if (DEBUG) enex("User::setGames()");
	}

	public function setGamesId($newIds) {
		$this->gamesId = $newIds;
		if (DEBUG) enex("User::setGamesId()");
	}

	public function addGame($game) {
		if (DEBUG) enter("User::addGame($game)");
		$this->games->addGame($game);
		array_push($this->gamesId, $game->getId);
		if (DEBUG) ex("User::addGame($game)");
	}
}
?>